unit oAgentBoss;

interface

uses uOSPABA;

type
  TAssitantBoss = class(tContinualAssistant)
    procedure ProcessMessage(var parMessage: TMessageForm); override;
  end;

  TAgentBoss = class(TAgent)
    strict private
      aAssistant: TAssitantBoss;
    public
      property Assistant: TAssitantBoss read aAssistant write aAssistant;
      constructor Create(paID: Cardinal; paMySim: TSimulation; paParent: tAgent);
  end;

  TManagerBoss = class(TManager)
   public
    procedure ProcessMessage(var paMessage: TMessageForm); override;
  end;

implementation

uses oSimulation, Dialogs, SysUtils;

{ TManazerModelu }

procedure TManagerBoss.ProcessMessage(var paMessage: TMessageForm);
var msg: TPSMessage;
begin
  with (MySim as TPedSimulation) do
  case paMessage.Code of

    mcInit: begin
      msg := paMessage.CreateCopy as TPSMessage;
      msg.Addressee := AgentBoss.Assistant;
      StartContinualAssistant(msg);
      paMessage.Addressee := AgentEnviroment;
      paMessage.Code := mcInitO;
      notice(paMessage);
    end;

    mcPrichodCM: begin
      paMessage.Code := mcPrichodCT;
      paMessage.Addressee := AgentTerminal;
      notice(paMessage);
    end;

    mcOdchodCT: begin
      paMessage.Code := mcOdchodCM;
      paMessage.Addressee := AgentEnviroment;
      notice(paMessage);
    end;
  end;
end;

{ TAgentModelu }

constructor TAgentBoss.Create(paID: Cardinal; paMySim: TSimulation;
  paParent: tAgent);
begin
  inherited Create(paID, paMySim, paParent);
  TManagerBoss.Create(IDManazerModelu, Self, NoMOPN);
  aAssistant := TAssitantBoss.Create(IDAsistentModelu,Self,NoMOPN);
  AddOwnMessage(mcInit);
  AddOwnMessage(mcPrichodCM);
  AddOwnMessage(mcOdchodCT);
end;

{ TAssitantBoss }

procedure TAssitantBoss.ProcessMessage(var parMessage: TMessageForm);
begin
  case parMessage.Code of

    mcStart:
    begin
      parMessage.Code := mcSpomal;
      Hold(0,parMessage);
    end;

    mcSpomal:
    begin
      with MySim as TPedSimulation do
        begin
          if SimGUI.Vypisovat then
            begin
              SysUtils.Sleep(SimGUI.ZaspatNa);
              SimGUI.Step;
            end;
          hold(SimGUI.ZaspatKazdych,parMessage);
        end;
    end;

  end;
end;

end.
